<?php

namespace app\admin\controller\user;

use app\admin\model\Admin;
use app\admin\model\User;
use app\common\controller\Backend;
use app\common\model\Attachment;
use fast\Date;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\Validate;

class Userlockcode extends Backend
{
    protected $searchFields = 'id,user.mobile,lockcode,user.companyname';
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
    }
    public function userlockcodesearch()
    {
        $where = [];
        if ($this->request->isPost()) {
            $searchtime = $this->request->request('searchtime');
            if ($searchtime == 1) {
                $start = strtotime('-7 days 00:00:00');
                $end = strtotime(date("Y-m-d 23:59:59"));
                $where['createtime'] = ['BETWEEN', [$start, $end]];
            }elseif ($searchtime == 2){
                $start = strtotime('-1 month 00:00:00');
                $end = strtotime(date("Y-m-d 23:59:59"));
                $where['createtime'] = ['BETWEEN', [$start, $end]];
            }elseif ($searchtime == 3){
                $start = strtotime('-1 year 00:00:00');
                $end = strtotime(date("Y-m-d 23:59:59"));
                $where['createtime'] = ['BETWEEN', [$start, $end]];
            }
        }

        $totalsearchs = Db::name('user_lockcode_searchfilelog')->where($where)->sum('num');
        if ($this->request->isPost()) {
            $this->success('', '', ['totalsearchs'=>$totalsearchs]);
        }
        $this->view->assign('totalsearchs',$totalsearchs);
        return $this->view->fetch();
    }
}